
package com.j2eefast.bussiness.contract.controller;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import com.j2eefast.bussiness.contract.entity.BusDepreciationEntity;
import com.j2eefast.bussiness.contract.entity.BusEquipmentRecordsEntity;
import com.j2eefast.bussiness.contract.entity.BusInstallsEntity;
import com.j2eefast.bussiness.contract.entity.BusRepairEntity;
import com.j2eefast.bussiness.contract.service.BusClassifyService;
import com.j2eefast.bussiness.contract.service.BusEquipmentRecordsService;
import com.j2eefast.bussiness.contract.service.BusInstallsService;
import com.j2eefast.bussiness.contract.service.BusRepairService;
import com.j2eefast.bussiness.contract.utils.MonthSheetWriteHandler;
import com.j2eefast.common.core.business.annotaion.BussinessLog;
import com.j2eefast.common.core.controller.BaseController;
import com.j2eefast.common.core.enums.BusinessType;
import com.j2eefast.common.core.utils.PageUtil;
import com.j2eefast.common.core.utils.ResponseData;
import com.j2eefast.common.core.utils.ToolUtil;
import com.j2eefast.common.core.utils.ValidatorUtil;
import com.j2eefast.framework.annotation.RepeatSubmit;
import com.j2eefast.framework.utils.Constant;
import com.j2eefast.framework.utils.Global;
import com.j2eefast.framework.utils.UserUtils;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;


/**
 * <p>维修管理</p>
 *
 * @author: summer
 * @date: 2021-06-06 14:41
 * @web: http://www.letukeji.cn
 * @version: 1.0.1
 */
@Controller
@RequestMapping("/bus/equipmentRecord")
public class BusEquipmentRecordsController extends BaseController {

	private String urlPrefix = "modules/bus/equipmentRecord";
	@Autowired
	private BusEquipmentRecordsService busEquipmentRecordsService;

	@RequiresPermissions("bus:equipmentRecord:view")
	@GetMapping()
	public String process() {
		return urlPrefix + "/index";
	}

	@RequestMapping("/list")
	@RequiresPermissions("bus:equipmentRecord:list")
	@ResponseBody
	public ResponseData list(@RequestParam Map<String, Object> params) {
		PageUtil page = busEquipmentRecordsService.findPage(params);
		return success(page);
	}

	/**
	 * 删除
	 */
	@BussinessLog(title = "删除", businessType = BusinessType.DELETE)
	@RequestMapping( value = "/del", method = RequestMethod.POST)
	@RequiresPermissions("bus:equipmentRecord:del")
	@RequiresRoles(Constant.SU_ADMIN)
	@ResponseBody
	public ResponseData delete(Long[] ids) {
		return busEquipmentRecordsService.deleteByIds(ids)?success(): error("删除失败!");
	}


	/**
	 * 修改出入库 页面
	 */
	@RequiresPermissions("bus:equipmentRecord:edit")
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap) {
		System.out.println(id);
		BusEquipmentRecordsEntity busEquipmentRecordsEntity = busEquipmentRecordsService.getById(id);
		System.out.println(busEquipmentRecordsEntity.getId());
		mmap.put("equipmentRecords", busEquipmentRecordsEntity);

		return urlPrefix + "/edit";
	}

	/**
	 * 修改出入库保存
	 */
	@RepeatSubmit
	@RequiresPermissions("bus:equipmentRecord:edit")
	@BussinessLog(title = "修改", businessType = BusinessType.UPDATE)
	@RequestMapping(value = "/edit", method = RequestMethod.POST)
	@ResponseBody
	public ResponseData edit(BusEquipmentRecordsEntity busEquipmentRecordsEntity) {
		ValidatorUtil.validateEntity(busEquipmentRecordsEntity);
		Date date = new Date();//创建一个时间对象，获取到当前的时间
		busEquipmentRecordsEntity.setUpdateTime(date);
		String userName=UserUtils.getUserInfo().getName();
		busEquipmentRecordsEntity.setCreateBy(userName);
		return busEquipmentRecordsService.updateById(busEquipmentRecordsEntity) ? success() : error("修改失败!");
	}

	/**
	 * 新增参数配置
	 */
	@RequiresPermissions("bus:equipmentRecord:add")
	@GetMapping("/add")
	public String add(ModelMap mmap) {
//		List<BusInstallsEntity> busInstallsEntity=busInstallsService.getInstallsList();

		return urlPrefix + "/add";
	}




	/**
	 * 新增保存
	 */
	@RepeatSubmit
	@RequiresPermissions("bus:equipmentRecord:add")
	@BussinessLog(title = "保存", businessType = BusinessType.INSERT)
	@RequestMapping(value = "/add", method = RequestMethod.POST)
	@ResponseBody
	public ResponseData addSave(@Validated BusEquipmentRecordsEntity busEquipmentRecordsEntity) {
		//校验参数
		ValidatorUtil.validateEntity(busEquipmentRecordsEntity);
		return busEquipmentRecordsService.saves(busEquipmentRecordsEntity) ? success() : error("新增失败!");
	}

	/**
	 * 修改出入库保存
	 */

	@RequiresPermissions("bus:equipmentRecord:checkout")
	@BussinessLog(title = "报废", businessType = BusinessType.INSERT)
	@RequestMapping(value = "/checkout", method = RequestMethod.POST)
	@ResponseBody
//	@GetMapping("/checkout/{id}")
	public ResponseData checkout(String id, ModelMap mmap) {
		System.out.println("1111111111111111111111");
		ValidatorUtil.validateEntity(id);
		Long ids=Long.parseLong(id);
		return busEquipmentRecordsService.updateCheck(ids) ? success() : error("修改失败!");
	}







}
